﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.CampaignBehaviors.PlayerTownVisitCampaignBehavior
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.ComponentInterfaces;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.GameMenus;
using TaleWorlds.CampaignSystem.GameState;
using TaleWorlds.CampaignSystem.Inventory;
using TaleWorlds.CampaignSystem.Overlay;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.CampaignSystem.Settlements.Locations;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;

#nullable disable
namespace TaleWorlds.CampaignSystem.CampaignBehaviors
{
  public class PlayerTownVisitCampaignBehavior : CampaignBehaviorBase
  {
    private CampaignTime _lastTimeRelationGivenPathfinder = CampaignTime.Zero;
    private CampaignTime _lastTimeRelationGivenWaterDiviner = CampaignTime.Zero;

    public override void RegisterEvents()
    {
      CampaignEvents.SettlementEntered.AddNonSerializedListener((object) this, new Action<MobileParty, Settlement, Hero>(this.OnSettlementEntered));
      CampaignEvents.OnSettlementLeftEvent.AddNonSerializedListener((object) this, new Action<MobileParty, Settlement>(this.OnSettlementLeft));
      CampaignEvents.OnSessionLaunchedEvent.AddNonSerializedListener((object) this, new Action<CampaignGameStarter>(this.AddGameMenus));
    }

    public override void SyncData(IDataStore dataStore)
    {
      dataStore.SyncData<CampaignTime>("_lastTimeRelationGivenPathfinder", ref this._lastTimeRelationGivenPathfinder);
      dataStore.SyncData<CampaignTime>("_lastTimeRelationGivenWaterDiviner", ref this._lastTimeRelationGivenWaterDiviner);
    }

    protected void AddGameMenus(CampaignGameStarter campaignGameSystemStarter)
    {
      campaignGameSystemStarter.AddGameMenu("town", "{=!}{SETTLEMENT_INFO}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_on_init), GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("town", "town_streets", "{=R5ObSaUN}Take a walk around the town center", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_streets_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_streets_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_keep", "{=!}{GO_TO_KEEP_TEXT}", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_go_to_keep_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_go_to_keep_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_arena", "{=CfDlOdTH}Go to the arena", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_go_to_arena_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town_arena")));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_backstreet", "{=l9sFJawW}Go to the tavern district", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_go_to_tavern_district_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town_backstreet")));
      campaignGameSystemStarter.AddGameMenuOption("town", "manage_production", "{=dgf6q4qB}Manage town", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_manage_town_on_condition), (GameMenuOption.OnConsequenceDelegate) null);
      campaignGameSystemStarter.AddGameMenuOption("town", "manage_production_cheat", "{=zZ3GqbzC}Manage town (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_manage_town_cheat_on_condition), (GameMenuOption.OnConsequenceDelegate) null);
      campaignGameSystemStarter.AddGameMenuOption("town", "recruit_volunteers", "{=E31IJyqs}Recruit troops", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_recruit_troops_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_recruit_volunteers_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town", "trade", "{=GmcgoiGy}Trade", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_trade_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_market_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_smithy", "{=McHsHbH8}Enter smithy", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_craft_item_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => CraftingHelper.OpenCrafting(CraftingTemplate.All[0])));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_wait", "{=zEoHYEUS}Wait here for some time", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_wait_here_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town_wait_menus")));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_return_to_army", "{=SK43eB6y}Return to Army", new GameMenuOption.OnConditionDelegate(this.game_menu_return_to_army_on_condition), new GameMenuOption.OnConsequenceDelegate(this.game_menu_return_to_army_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town", "town_leave", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_leave_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_settlement_leave_on_consequence), true);
      campaignGameSystemStarter.AddGameMenu("town_keep", "{=!}{SETTLEMENT_INFO}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_keep_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "town_lords_hall", "{=dv2ZNazN}Go to the lord's hall", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_go_to_lords_hall_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_lordshall_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "town_lords_hall_cheat", "{=!}Go to the lord's hall (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_lords_hall_cheat_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_lordshall_cheat_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "town_lords_hall_go_to_dungeon", "{=etjMHPjQ}Go to dungeon", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_go_dungeon_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_go_dungeon_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "leave_troops_to_garrison", "{=7J9KNFTz}Donate troops to garrison", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_leave_troops_garrison_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_leave_troops_garrison_on_consequece));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "manage_garrison", "{=QazTA60M}Manage garrison", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_manage_garrison_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_manage_garrison_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "open_stash", "{=xl4K9ecB}Open stash", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_open_stash_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_open_stash_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep", "town_castle_back", "{=qWAmxyYz}Back to town center", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town")), true);
      campaignGameSystemStarter.AddGameMenu("town_keep_dungeon", "{=!}{PRISONER_INTRODUCTION}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_keep_dungeon_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("town_keep_dungeon", "town_prison", "{=UnQFawna}Enter the dungeon", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_enter_the_dungeon_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_dungeon_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep_dungeon", "town_prison_cheat", "{=KBxajw4c}Enter the dungeon (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_dungeon_cheat_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_dungeon_cheat_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep_dungeon", "town_prison_leave_prisoners", "{=kmsNUfbA}Donate prisoners", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_leave_prisoners_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_leave_prisoners_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep_dungeon", "town_prison_manage_prisoners", "{=VXkL5Ysd}Manage prisoners", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_manage_prisoners_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_manage_prisoners_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep_dungeon", "town_keep_dungeon_back", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town_keep")), true);
      campaignGameSystemStarter.AddGameMenu("town_keep_bribe", "{=yyz111nn}The guards say that they can't just let anyone in.", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_keep_bribe_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("town_keep_bribe", "town_keep_bribe_pay", "{=fxEka7Bm}Pay a {AMOUNT}{GOLD_ICON} bribe to enter the keep", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_bribe_pay_bribe_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_bribe_pay_bribe_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_keep_bribe", "town_keep_bribe_back", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town")), true);
      campaignGameSystemStarter.AddGameMenu("town_enemy_town_keep", "{=!}{SCOUT_KEEP_TEXT}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_enemy_keep_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("town_enemy_town_keep", "settlement_go_back_to_center", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town")), true);
      campaignGameSystemStarter.AddGameMenu("town_backstreet", "{=Zwy8JybD}You are in the backstreets. The local tavern seems to be attracting its usual crowd.", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_backstreet_on_init), GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("town_backstreet", "town_tavern", "{=qcl3YTPh}Visit the tavern", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.visit_the_tavern_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_tavern_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_backstreet", "sell_all_prisoners", "{=xZIBKK0v}Ransom your prisoners ({RANSOM_AMOUNT}{GOLD_ICON})", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.SellPrisonersCondition), (GameMenuOption.OnConsequenceDelegate) (x => PlayerTownVisitCampaignBehavior.SellAllTransferablePrisoners()));
      campaignGameSystemStarter.AddGameMenuOption("town_backstreet", "sell_some_prisoners", "{=Q8VN9UCq}Choose the prisoners to be ransomed", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.SellPrisonerOneStackCondition), (GameMenuOption.OnConsequenceDelegate) (x => PlayerTownVisitCampaignBehavior.ChooseRansomPrisoners()));
      campaignGameSystemStarter.AddGameMenuOption("town_backstreet", "town_backstreet_back", "{=qWAmxyYz}Back to town center", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town")), true);
      campaignGameSystemStarter.AddGameMenu("town_arena", "{=5id9mGrc}You are near the arena. {ADDITIONAL_STRING}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_arena_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("town_arena", "town_enter_arena", "{=YQ3vm6er}Enter the arena", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_enter_the_arena_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_arena_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("town_arena", "town_arena_back", "{=qWAmxyYz}Back to town center", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town")), true);
      campaignGameSystemStarter.AddGameMenu("settlement_player_unconscious", "{=S5OEsjwg}You slip into unconsciousness. After a little while some of the friendlier locals manage to bring you around. A little confused but without any serious injuries, you resolve to be more careful next time.", (OnInitDelegate) null, GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("settlement_player_unconscious", "continue", "{=DM6luo3c}Continue", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.continue_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.settlement_player_unconscious_continue_on_consequence));
      campaignGameSystemStarter.AddWaitGameMenu("settlement_wait", "{=8AbHxCM8}{CAPTIVITY_TEXT}\nWaiting in captivity...", new OnInitDelegate(PlayerTownVisitCampaignBehavior.settlement_wait_on_init), new OnConditionDelegate(PlayerTownVisitCampaignBehavior.wait_menu_prisoner_wait_on_condition), (OnConsequenceDelegate) null, new OnTickDelegate(PlayerTownVisitCampaignBehavior.wait_menu_settlement_wait_on_tick), GameMenu.MenuAndOptionType.WaitMenuHideProgressAndHoursOption);
      campaignGameSystemStarter.AddWaitGameMenu("town_wait_menus", "{=ydbVysqv}You are waiting in {CURRENT_SETTLEMENT}.", new OnInitDelegate(this.game_menu_settlement_wait_on_init), new OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_wait_on_condition), (OnConsequenceDelegate) null, (OnTickDelegate) ((args, dt) => this.SwitchToMenuIfThereIsAnInterrupt(args.MenuContext.GameMenu.StringId)), GameMenu.MenuAndOptionType.WaitMenuHideProgressAndHoursOption, GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("town_wait_menus", "wait_leave", "{=UqDNAZqM}Stop waiting", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (args =>
      {
        PlayerEncounter.Current.IsPlayerWaiting = false;
        this.SwitchToMenuIfThereIsAnInterrupt(args.MenuContext.GameMenu.StringId);
      }), true);
      campaignGameSystemStarter.AddGameMenu("castle", "{=!}{SETTLEMENT_INFO}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_on_init), GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("castle", "take_a_walk_around_the_castle", "{=R92XzKXE}Take a walk around the castle", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_take_a_walk_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_take_a_walk_around_the_castle_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "castle_lords_hall", "{=dv2ZNazN}Go to the lord's hall", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_lords_hall_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_lordshall_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "castle_lords_hall_cheat", "{=dl6YxNTT}Go to the lord's hall (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_lords_hall_cheat_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_lordshall_cheat_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "castle_prison", "{=esSm5V6t}Go to the dungeon", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_the_dungeon_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_keep_dungeon_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "castle_prison_cheat", "{=pa7oiQb1}Go to the dungeon (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_dungeon_cheat_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_dungeon_cheat_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "manage_garrison", "{=QazTA60M}Manage garrison", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_manage_garrison_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_manage_garrison_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "manage_production", "{=Ll1EJHXF}Manage castle", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_manage_castle_on_condition), (GameMenuOption.OnConsequenceDelegate) null);
      campaignGameSystemStarter.AddGameMenuOption("castle", "open_stash", "{=xl4K9ecB}Open stash", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_open_stash_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_keep_open_stash_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "leave_troops_to_garrison", "{=7J9KNFTz}Donate troops to garrison", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_leave_troops_garrison_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_leave_troops_garrison_on_consequece));
      campaignGameSystemStarter.AddGameMenuOption("castle", "town_wait", "{=zEoHYEUS}Wait here for some time", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_wait_here_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("town_wait_menus")));
      campaignGameSystemStarter.AddGameMenuOption("castle", "castle_return_to_army", "{=SK43eB6y}Return to Army", new GameMenuOption.OnConditionDelegate(this.game_menu_return_to_army_on_condition), new GameMenuOption.OnConsequenceDelegate(this.game_menu_return_to_army_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle", "leave", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_leave_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_settlement_leave_on_consequence), true);
      campaignGameSystemStarter.AddGameMenu("castle_lords_hall_bribe", "{=yyz111nn}The guards say that they can't just let anyone in.", (OnInitDelegate) null, GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("castle_lords_hall_bribe", "castle_bribe_pay", "{=3lxq5fvI}Pay a {AMOUNT}{GOLD_ICON} bribe to go to the lord's hall.", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_lordshall_bribe_pay_bribe_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_lordshall_bribe_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle_lords_hall_bribe", "castle_bribe_back", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("castle")), true);
      campaignGameSystemStarter.AddGameMenu("castle_dungeon", "{=!}{PRISONER_INTRODUCTION}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.town_keep_dungeon_on_init), GameOverlays.MenuOverlayType.SettlementWithCharacters);
      campaignGameSystemStarter.AddGameMenuOption("castle_dungeon", "town_prison", "{=UnQFawna}Enter the dungeon", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_enter_the_dungeon_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_dungeon_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle_dungeon", "town_prison_cheat", "{=KBxajw4c}Enter the dungeon (Cheat)", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_go_to_dungeon_cheat_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_dungeon_cheat_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle_dungeon", "town_prison_leave_prisoners", "{=kmsNUfbA}Donate prisoners", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_leave_prisoners_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_leave_prisoners_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle_dungeon", "town_prison_manage_prisoners", "{=VXkL5Ysd}Manage prisoners", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_manage_prisoners_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_castle_manage_prisoners_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("castle_dungeon", "town_keep_dungeon_back", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), (GameMenuOption.OnConsequenceDelegate) (x => GameMenu.SwitchToMenu("castle")), true);
      campaignGameSystemStarter.AddGameMenu("village", "{=!}{SETTLEMENT_INFO}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.game_menu_village_on_init), GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("village", "village_center", "{=U4azeSib}Take a walk through the lands", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_village_village_center_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_village_village_center_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("village", "recruit_volunteers", "{=E31IJyqs}Recruit troops", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_recruit_volunteers_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_recruit_volunteers_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("village", "trade", "{=VN4ctHIU}Buy products", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_village_buy_good_on_condition), (GameMenuOption.OnConsequenceDelegate) null);
      campaignGameSystemStarter.AddGameMenuOption("village", "village_wait", "{=zEoHYEUS}Wait here for some time", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_wait_here_on_condition), new GameMenuOption.OnConsequenceDelegate(this.game_menu_wait_village_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("village", "village_return_to_army", "{=SK43eB6y}Return to Army", new GameMenuOption.OnConditionDelegate(this.game_menu_return_to_army_on_condition), new GameMenuOption.OnConsequenceDelegate(this.game_menu_return_to_army_on_consequence));
      campaignGameSystemStarter.AddGameMenuOption("village", "leave", "{=3sRdGQou}Leave", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_town_town_leave_on_condition), new GameMenuOption.OnConsequenceDelegate(PlayerTownVisitCampaignBehavior.game_menu_settlement_leave_on_consequence), true);
      campaignGameSystemStarter.AddWaitGameMenu("village_wait_menus", "{=lsBuV9W7}You are waiting in the village.", new OnInitDelegate(this.game_menu_settlement_wait_on_init), new OnConditionDelegate(PlayerTownVisitCampaignBehavior.game_menu_village_wait_on_condition), (OnConsequenceDelegate) null, (OnTickDelegate) ((args, dt) => this.SwitchToMenuIfThereIsAnInterrupt(args.MenuContext.GameMenu.StringId)), GameMenu.MenuAndOptionType.WaitMenuHideProgressAndHoursOption, GameOverlays.MenuOverlayType.SettlementWithBoth);
      campaignGameSystemStarter.AddGameMenuOption("village_wait_menus", "wait_leave", "{=UqDNAZqM}Stop waiting", new GameMenuOption.OnConditionDelegate(PlayerTownVisitCampaignBehavior.back_on_condition), new GameMenuOption.OnConsequenceDelegate(this.game_menu_stop_waiting_at_village_on_consequence), true);
      campaignGameSystemStarter.AddWaitGameMenu("prisoner_wait", "{=!}{CAPTIVITY_TEXT}", new OnInitDelegate(PlayerTownVisitCampaignBehavior.wait_menu_prisoner_wait_on_init), new OnConditionDelegate(PlayerTownVisitCampaignBehavior.wait_menu_prisoner_wait_on_condition), (OnConsequenceDelegate) null, new OnTickDelegate(PlayerTownVisitCampaignBehavior.wait_menu_prisoner_wait_on_tick), GameMenu.MenuAndOptionType.WaitMenuHideProgressAndHoursOption);
    }

    private void game_menu_settlement_wait_on_init(MenuCallbackArgs args)
    {
      string menuID = PlayerEncounter.EncounterSettlement.IsVillage ? "village" : (PlayerEncounter.EncounterSettlement.IsTown ? "town" : (PlayerEncounter.EncounterSettlement.IsCastle ? "castle" : (string) null));
      if (menuID != null)
        PlayerTownVisitCampaignBehavior.UpdateMenuLocations(menuID);
      if (PlayerEncounter.Current == null)
        return;
      PlayerEncounter.Current.IsPlayerWaiting = true;
    }

    private static void OpenMissionWithSettingPreviousLocation(
      string previousLocationId,
      string missionLocationId)
    {
      Campaign.Current.GameMenuManager.NextLocation = LocationComplex.Current.GetLocationWithId(missionLocationId);
      Campaign.Current.GameMenuManager.PreviousLocation = LocationComplex.Current.GetLocationWithId(previousLocationId);
      PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(Campaign.Current.GameMenuManager.NextLocation);
      Campaign.Current.GameMenuManager.NextLocation = (Location) null;
      Campaign.Current.GameMenuManager.PreviousLocation = (Location) null;
    }

    private void game_menu_stop_waiting_at_village_on_consequence(MenuCallbackArgs args)
    {
      EnterSettlementAction.ApplyForParty(MobileParty.MainParty, MobileParty.MainParty.LastVisitedSettlement);
      GameMenu.SwitchToMenu("village");
    }

    private static bool continue_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Continue;
      return true;
    }

    private static bool game_menu_castle_go_to_the_dungeon_on_condition(MenuCallbackArgs args)
    {
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterDungeon(Settlement.CurrentSettlement, out accessDetails);
      if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.LimitedAccess)
      {
        args.Tooltip = new TextObject("{=aPoS8wOW}You have limited access to Dungeon.");
        args.IsEnabled = false;
      }
      if (FactionManager.IsAtWarAgainstFaction(Settlement.CurrentSettlement.MapFaction, Hero.MainHero.MapFaction))
      {
        args.Tooltip = new TextObject("{=h9i9VXLd}You cannot enter an enemy lord's hall.");
        args.IsEnabled = false;
      }
      args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "prison")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      return true;
    }

    private static bool game_menu_castle_enter_the_dungeon_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "prison")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      return true;
    }

    private static bool game_menu_castle_go_to_dungeon_cheat_on_condition(MenuCallbackArgs args)
    {
      return Game.Current.IsDevelopmentMode;
    }

    private static bool game_menu_castle_leave_prisoners_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.DonatePrisoners;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      if (!currentSettlement.IsFortification)
        return false;
      if (currentSettlement.Party != null && currentSettlement.Party.PrisonerSizeLimit <= currentSettlement.Party.NumberOfPrisoners)
      {
        args.IsEnabled = false;
        args.Tooltip = GameTexts.FindText("str_dungeon_size_limit_exceeded");
        args.Tooltip.SetTextVariable("TROOP_NUMBER", currentSettlement.Party.NumberOfPrisoners);
      }
      return currentSettlement.OwnerClan != Clan.PlayerClan && currentSettlement.MapFaction == Hero.MainHero.MapFaction;
    }

    private static bool game_menu_castle_manage_prisoners_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.ManagePrisoners;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      return currentSettlement.OwnerClan == Clan.PlayerClan && currentSettlement.MapFaction == Hero.MainHero.MapFaction && currentSettlement.IsFortification;
    }

    private static void game_menu_castle_leave_prisoners_on_consequence(MenuCallbackArgs args)
    {
      PartyScreenManager.OpenScreenAsDonatePrisoners();
    }

    private static void game_menu_castle_manage_prisoners_on_consequence(MenuCallbackArgs args)
    {
      PartyScreenManager.OpenScreenAsManagePrisoners();
    }

    private static bool game_menu_town_go_to_keep_on_condition(MenuCallbackArgs args)
    {
      TextObject text = new TextObject("{=XZFQ1Jf6}Go to the keep");
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterLordsHall(Settlement.CurrentSettlement, out accessDetails);
      if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.NoAccess)
      {
        args.IsEnabled = false;
        PlayerTownVisitCampaignBehavior.SetLordsHallAccessLimitationReasonText(args, accessDetails);
      }
      else if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.LimitedAccess && accessDetails.LimitedAccessSolution == SettlementAccessModel.LimitedAccessSolution.Disguise)
      {
        text = new TextObject("{=1GPa9aTQ}Scout the keep");
        args.Tooltip = new TextObject("{=ubOtRU3u}You have limited access to keep while in disguise.");
      }
      MBTextManager.SetTextVariable("GO_TO_KEEP_TEXT", text, false);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "lordshall" || x == "prison")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
      return true;
    }

    private static bool game_menu_go_to_tavern_district_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroAccessLocation(Settlement.CurrentSettlement, "tavern", out disableOption, out disabledText);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "tavern")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static bool game_menu_trade_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.Trade, out disableOption, out disabledText);
      args.optionLeaveType = GameMenuOption.LeaveType.Trade;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static bool game_menu_town_recruit_troops_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.RecruitTroops, out disableOption, out disabledText);
      args.optionLeaveType = GameMenuOption.LeaveType.Recruit;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static bool game_menu_wait_here_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.WaitInSettlement, out disableOption, out disabledText);
      args.optionLeaveType = GameMenuOption.LeaveType.Wait;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private void game_menu_wait_village_on_consequence(MenuCallbackArgs args)
    {
      GameMenu.SwitchToMenu("village_wait_menus");
      LeaveSettlementAction.ApplyForParty(MobileParty.MainParty);
    }

    private bool game_menu_return_to_army_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Wait;
      return MobileParty.MainParty.Army != null && MobileParty.MainParty.Army.LeaderParty != MobileParty.MainParty;
    }

    private void game_menu_return_to_army_on_consequence(MenuCallbackArgs args)
    {
      GameMenu.SwitchToMenu("army_wait_at_settlement");
      if (!MobileParty.MainParty.CurrentSettlement.IsVillage)
        return;
      PlayerEncounter.LeaveSettlement();
      PlayerEncounter.Finish();
    }

    private static bool game_menu_castle_take_a_walk_on_condition(MenuCallbackArgs args)
    {
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "center")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return true;
    }

    private static void game_menu_town_go_to_keep_on_consequence(MenuCallbackArgs args)
    {
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterLordsHall(Settlement.CurrentSettlement, out accessDetails);
      switch (accessDetails.AccessLevel)
      {
        case SettlementAccessModel.AccessLevel.LimitedAccess:
          if (accessDetails.LimitedAccessSolution == SettlementAccessModel.LimitedAccessSolution.Bribe)
          {
            GameMenu.SwitchToMenu("town_keep_bribe");
            return;
          }
          if (accessDetails.LimitedAccessSolution == SettlementAccessModel.LimitedAccessSolution.Disguise)
          {
            GameMenu.SwitchToMenu("town_enemy_town_keep");
            return;
          }
          break;
        case SettlementAccessModel.AccessLevel.FullAccess:
          GameMenu.SwitchToMenu("town_keep");
          return;
      }
      Debug.FailedAssert("invalid LimitedAccessSolution or AccessLevel for town keep", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\CampaignBehaviors\\PlayerTownVisitCampaignBehavior.cs", nameof (game_menu_town_go_to_keep_on_consequence), 477);
    }

    private static bool game_menu_go_dungeon_on_condition(MenuCallbackArgs args)
    {
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterDungeon(Settlement.CurrentSettlement, out accessDetails);
      if (Settlement.CurrentSettlement.BribePaid < Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterDungeon(Settlement.CurrentSettlement) && accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.LimitedAccess)
      {
        args.Tooltip = new TextObject("{=aPoS8wOW}You have limited access to Dungeon.");
        args.IsEnabled = false;
      }
      args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "prison")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      return true;
    }

    private static void game_menu_go_dungeon_on_consequence(MenuCallbackArgs args)
    {
      GameMenu.SwitchToMenu("town_keep_dungeon");
    }

    private static bool back_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Leave;
      return true;
    }

    private static bool visit_the_tavern_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "tavern")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      return true;
    }

    private static bool game_menu_town_go_to_arena_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroAccessLocation(Settlement.CurrentSettlement, "arena", out disableOption, out disabledText);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "arena")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Submenu;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static bool game_menu_town_enter_the_arena_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.WalkAroundTheArena, out disableOption, out disabledText);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "arena")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static bool game_menu_craft_item_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(Settlement.CurrentSettlement, SettlementAccessModel.SettlementAction.Craft, out disableOption, out disabledText);
      args.optionLeaveType = GameMenuOption.LeaveType.Craft;
      ICraftingCampaignBehavior campaignBehavior = Campaign.Current.GetCampaignBehavior<ICraftingCampaignBehavior>();
      CraftingCampaignBehavior.CraftingOrderSlots craftingOrderSlots;
      if (Settlement.CurrentSettlement.IsTown && campaignBehavior != null && campaignBehavior.CraftingOrders != null && campaignBehavior.CraftingOrders.TryGetValue(Settlement.CurrentSettlement.Town, out craftingOrderSlots) && craftingOrderSlots.CustomOrders.Count > 0)
        args.OptionQuestData |= GameMenuOption.IssueQuestFlags.ActiveIssue;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    public static void wait_menu_prisoner_wait_on_init(MenuCallbackArgs args)
    {
      TextObject text1 = args.MenuContext.GameMenu.GetText();
      int captiveTimeInDays = PlayerCaptivity.CaptiveTimeInDays;
      TextObject text2;
      if (captiveTimeInDays == 0)
      {
        text2 = GameTexts.FindText("str_prisoner_of_party_menu_text");
      }
      else
      {
        text2 = GameTexts.FindText("str_prisoner_of_party_for_days_menu_text");
        text2.SetTextVariable("NUMBER_OF_DAYS", captiveTimeInDays);
        text2.SetTextVariable("PLURAL", captiveTimeInDays > 1 ? 1 : 0);
      }
      text2.SetTextVariable("PARTY_NAME", Hero.MainHero.PartyBelongedToAsPrisoner != null ? Hero.MainHero.PartyBelongedToAsPrisoner.Name : TextObject.Empty);
      TextObject variable = text2;
      text1.SetTextVariable("CAPTIVITY_TEXT", variable);
    }

    [GameMenuInitializationHandler("settlement_wait")]
    public static void wait_menu_prisoner_settlement_wait_ui_on_init(MenuCallbackArgs args)
    {
      if (Hero.MainHero.IsFemale)
        args.MenuContext.SetBackgroundMeshName("wait_prisoner_female");
      else
        args.MenuContext.SetBackgroundMeshName("wait_prisoner_male");
    }

    public static bool wait_menu_prisoner_wait_on_condition(MenuCallbackArgs args) => true;

    public static void wait_menu_prisoner_wait_on_tick(MenuCallbackArgs args, CampaignTime dt)
    {
      int captiveTimeInDays = PlayerCaptivity.CaptiveTimeInDays;
      if (captiveTimeInDays == 0)
        return;
      TextObject text1 = args.MenuContext.GameMenu.GetText();
      TextObject text2 = GameTexts.FindText("str_prisoner_of_party_for_days_menu_text");
      text2.SetTextVariable("NUMBER_OF_DAYS", captiveTimeInDays);
      text2.SetTextVariable("PLURAL", captiveTimeInDays > 1 ? 1 : 0);
      text2.SetTextVariable("PARTY_NAME", PlayerCaptivity.CaptorParty.Name);
      TextObject variable = text2;
      text1.SetTextVariable("CAPTIVITY_TEXT", variable);
    }

    public static void wait_menu_settlement_wait_on_tick(MenuCallbackArgs args, CampaignTime dt)
    {
      int captiveTimeInDays = PlayerCaptivity.CaptiveTimeInDays;
      if (captiveTimeInDays == 0)
        return;
      TextObject variable1 = Hero.MainHero.IsPrisoner ? Hero.MainHero.PartyBelongedToAsPrisoner.Settlement.Name : Settlement.CurrentSettlement.Name;
      TextObject text1 = args.MenuContext.GameMenu.GetText();
      TextObject text2 = GameTexts.FindText("str_prisoner_of_settlement_for_days_menu_text");
      text2.SetTextVariable("NUMBER_OF_DAYS", captiveTimeInDays);
      text2.SetTextVariable("PLURAL", captiveTimeInDays > 1 ? 1 : 0);
      text2.SetTextVariable("SETTLEMENT_NAME", variable1);
      TextObject variable2 = text2;
      text1.SetTextVariable("CAPTIVITY_TEXT", variable2);
    }

    private static bool SellPrisonersCondition(MenuCallbackArgs args)
    {
      if (PartyBase.MainParty.PrisonRoster.Count > 0)
      {
        int transferablePrisoners = PlayerTownVisitCampaignBehavior.GetRansomValueOfAllTransferablePrisoners();
        if (transferablePrisoners > 0)
        {
          MBTextManager.SetTextVariable("RANSOM_AMOUNT", transferablePrisoners);
          args.optionLeaveType = GameMenuOption.LeaveType.Ransom;
          return true;
        }
      }
      return false;
    }

    private static bool SellPrisonerOneStackCondition(MenuCallbackArgs args)
    {
      if (PartyBase.MainParty.PrisonRoster.Count <= 0)
        return false;
      args.optionLeaveType = GameMenuOption.LeaveType.Ransom;
      return true;
    }

    private static int GetRansomValueOfAllTransferablePrisoners()
    {
      int transferablePrisoners = 0;
      List<string> list = Campaign.Current.GetCampaignBehavior<IViewDataTracker>().GetPartyPrisonerLocks().ToList<string>();
      foreach (TroopRosterElement troopRosterElement in (List<TroopRosterElement>) PartyBase.MainParty.PrisonRoster.GetTroopRoster())
      {
        if (!list.Contains(troopRosterElement.Character.StringId))
          transferablePrisoners += Campaign.Current.Models.RansomValueCalculationModel.PrisonerRansomValue(troopRosterElement.Character, Hero.MainHero) * troopRosterElement.Number;
      }
      return transferablePrisoners;
    }

    private static void ChooseRansomPrisoners()
    {
      GameMenu.SwitchToMenu("town_backstreet");
      PartyScreenManager.OpenScreenAsRansom();
    }

    private static void SellAllTransferablePrisoners()
    {
      SellPrisonersAction.ApplyForSelectedPrisoners(PartyBase.MainParty, Settlement.CurrentSettlement.Party, MobilePartyHelper.GetPlayerPrisonersPlayerCanSell());
      GameMenu.SwitchToMenu("town_backstreet");
    }

    private static bool game_menu_castle_go_to_lords_hall_on_condition(MenuCallbackArgs args)
    {
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterLordsHall(Settlement.CurrentSettlement, out accessDetails);
      if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.NoAccess)
      {
        args.IsEnabled = false;
        PlayerTownVisitCampaignBehavior.SetLordsHallAccessLimitationReasonText(args, accessDetails);
      }
      else if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.LimitedAccess && accessDetails.LimitedAccessSolution == SettlementAccessModel.LimitedAccessSolution.Bribe && Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement) > Hero.MainHero.Gold)
      {
        args.IsEnabled = false;
        args.Tooltip = new TextObject("{=d0kbtGYn}You don't have enough gold.");
      }
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "lordshall")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return true;
    }

    private static void SetLordsHallAccessLimitationReasonText(
      MenuCallbackArgs args,
      SettlementAccessModel.AccessDetails accessDetails)
    {
      switch (accessDetails.AccessLimitationReason)
      {
        case SettlementAccessModel.AccessLimitationReason.HostileFaction:
          args.Tooltip = new TextObject("{=h9i9VXLd}You cannot enter an enemy lord's hall.");
          break;
        case SettlementAccessModel.AccessLimitationReason.LocationEmpty:
          args.Tooltip = new TextObject("{=cojKmfSk}There is no one inside.");
          break;
        default:
          Debug.FailedAssert(string.Format("{0} is not a valid no access reason for lord's hall", (object) accessDetails.AccessLimitationReason), "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\CampaignBehaviors\\PlayerTownVisitCampaignBehavior.cs", nameof (SetLordsHallAccessLimitationReasonText), 726);
          break;
      }
    }

    private static bool game_menu_town_keep_go_to_lords_hall_on_condition(MenuCallbackArgs args)
    {
      if (FactionManager.IsAtWarAgainstFaction(Settlement.CurrentSettlement.MapFaction, Hero.MainHero.MapFaction))
      {
        args.Tooltip = new TextObject("{=h9i9VXLd}You cannot enter an enemy lord's hall.");
        args.IsEnabled = false;
      }
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "lordshall")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return true;
    }

    private static bool game_menu_town_keep_bribe_pay_bribe_on_condition(MenuCallbackArgs args)
    {
      int toEnterLordsHall = Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement);
      MBTextManager.SetTextVariable("AMOUNT", toEnterLordsHall);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "lordshall")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      if (Hero.MainHero.Gold < toEnterLordsHall)
      {
        args.Tooltip = new TextObject("{=d0kbtGYn}You don't have enough gold.");
        args.IsEnabled = false;
      }
      return toEnterLordsHall > 0;
    }

    private static bool game_menu_castle_go_to_lords_hall_cheat_on_condition(MenuCallbackArgs args)
    {
      return Game.Current.IsDevelopmentMode;
    }

    private static void game_menu_castle_take_a_walk_around_the_castle_on_consequence(
      MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(LocationComplex.Current.GetLocationWithId("center"));
    }

    private static bool CheckAndOpenNextLocation(MenuCallbackArgs args)
    {
      if (Campaign.Current.GameMenuManager.NextLocation == null || !(GameStateManager.Current.ActiveState is MapState))
        return false;
      PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(Campaign.Current.GameMenuManager.NextLocation, Campaign.Current.GameMenuManager.PreviousLocation);
      switch (Campaign.Current.GameMenuManager.NextLocation.StringId)
      {
        case "center":
          if (Settlement.CurrentSettlement.IsCastle)
          {
            Campaign.Current.GameMenuManager.SetNextMenu("castle");
            break;
          }
          if (Settlement.CurrentSettlement.IsTown)
          {
            Campaign.Current.GameMenuManager.SetNextMenu("town");
            break;
          }
          if (Settlement.CurrentSettlement.IsVillage)
          {
            Campaign.Current.GameMenuManager.SetNextMenu("village");
            break;
          }
          Debug.FailedAssert("false", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\CampaignBehaviors\\PlayerTownVisitCampaignBehavior.cs", nameof (CheckAndOpenNextLocation), 809);
          break;
        case "tavern":
          Campaign.Current.GameMenuManager.SetNextMenu("town_backstreet");
          break;
        case "arena":
          Campaign.Current.GameMenuManager.SetNextMenu("town_arena");
          break;
        case "lordshall":
        case "prison":
          Campaign.Current.GameMenuManager.SetNextMenu("town_keep");
          break;
      }
      Campaign.Current.GameMenuManager.NextLocation = (Location) null;
      Campaign.Current.GameMenuManager.PreviousLocation = (Location) null;
      return true;
    }

    private static void game_menu_town_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.SetIntroductionText(Settlement.CurrentSettlement, false);
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      Campaign.Current.autoEnterTown = (PartyBase) null;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      MobileParty garrisonParty1 = Settlement.CurrentSettlement.Town.GarrisonParty;
      if ((garrisonParty1 != null ? (garrisonParty1.MemberRoster.Count <= 0 ? 1 : 0) : 0) != 0)
      {
        MobileParty garrisonParty2 = Settlement.CurrentSettlement.Town.GarrisonParty;
        if ((garrisonParty2 != null ? (garrisonParty2.PrisonRoster.Count <= 0 ? 1 : 0) : 0) != 0)
          DestroyPartyAction.Apply((PartyBase) null, Settlement.CurrentSettlement.Town.GarrisonParty);
      }
      args.MenuTitle = new TextObject("{=mVKcvY2U}Town Center");
    }

    private static void UpdateMenuLocations(string menuID)
    {
      Campaign.Current.GameMenuManager.MenuLocations.Clear();
      Settlement settlement = Settlement.CurrentSettlement == null ? MobileParty.MainParty.CurrentSettlement : Settlement.CurrentSettlement;
      switch (menuID)
      {
        case "castle":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("center"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("lordshall"));
          break;
        case "castle_dungeon":
        case "town_enemy_town_keep":
        case "town_keep_dungeon":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("prison"));
          break;
        case "castle_lords_hall_bribe":
          break;
        case "town":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("center"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("arena"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("house_1"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("house_2"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("house_3"));
          break;
        case "town_arena":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("arena"));
          break;
        case "town_backstreet":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("tavern"));
          break;
        case "town_center":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("center"));
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("arena"));
          break;
        case "town_keep":
          Campaign.Current.GameMenuManager.MenuLocations.Add(settlement.LocationComplex.GetLocationWithId("lordshall"));
          break;
        case "town_keep_bribe":
          break;
        case "village":
          Campaign.Current.GameMenuManager.MenuLocations.AddRange(settlement.LocationComplex.GetListOfLocations());
          break;
        default:
          Debug.FailedAssert("Could not get the associated locations for Game Menu: " + menuID, "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\CampaignBehaviors\\PlayerTownVisitCampaignBehavior.cs", nameof (UpdateMenuLocations), 916);
          Campaign.Current.GameMenuManager.MenuLocations.AddRange(settlement.LocationComplex.GetListOfLocations());
          break;
      }
    }

    private static void town_keep_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      PlayerTownVisitCampaignBehavior.SetIntroductionText(Settlement.CurrentSettlement, true);
      args.MenuTitle = new TextObject("{=723ig40Q}Keep");
    }

    private static void town_enemy_keep_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      PlayerTownVisitCampaignBehavior.SetIntroductionText(Settlement.CurrentSettlement, true);
      TextObject text = args.MenuContext.GameMenu.GetText();
      MobileParty garrisonParty = Settlement.CurrentSettlement.Town.GarrisonParty;
      string variable = (garrisonParty != null ? (garrisonParty.PrisonRoster.TotalHeroes > 0 ? 1 : 0) : 0) != 0 || Settlement.CurrentSettlement.Party.PrisonRoster.TotalHeroes > 0 ? "{=Tfb9LNAr}You have observed the comings and goings of the guards at the keep. You think you've identified a guard who might be approached and offered a bribe." : "{=qGUrhBpI}After spending time observing the keep and eavesdropping on the guards, you conclude that there are no prisoners here who you can liberate.";
      text.SetTextVariable("SCOUT_KEEP_TEXT", variable);
      args.MenuTitle = new TextObject("{=723ig40Q}Keep");
    }

    private static void town_keep_dungeon_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      args.MenuTitle = new TextObject("{=x04UGQDn}Dungeon");
      TextObject empty = TextObject.Empty;
      TextObject text;
      if (Settlement.CurrentSettlement.SettlementComponent.GetPrisonerHeroes().Count == 0)
      {
        text = new TextObject("{=O4flV28Q}There are no prisoners here.");
      }
      else
      {
        int count = Settlement.CurrentSettlement.SettlementComponent.GetPrisonerHeroes().Count;
        text = new TextObject("{=gAc8SWDt}There {?(PRISONER_COUNT > 1)}are {PRISONER_COUNT} prisoners{?}is 1 prisoner{\\?} here.");
        text.SetTextVariable("PRISONER_COUNT", count);
      }
      MBTextManager.SetTextVariable("PRISONER_INTRODUCTION", text, false);
    }

    private static void town_keep_bribe_on_init(MenuCallbackArgs args)
    {
      args.MenuTitle = new TextObject("{=723ig40Q}Keep");
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement) != 0)
        return;
      GameMenu.ActivateGameMenu("town_keep");
    }

    private static void town_backstreet_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      string name = Settlement.CurrentSettlement.Culture.StringId + "_tavern";
      args.MenuContext.SetBackgroundMeshName(name);
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      args.MenuTitle = new TextObject("{=a0MVffcN}Backstreet");
    }

    private static void town_arena_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (Settlement.CurrentSettlement != null && Settlement.CurrentSettlement.IsTown && Campaign.Current.TournamentManager.GetTournamentGame(Settlement.CurrentSettlement.Town) != null && Campaign.Current.IsDay)
        MBTextManager.SetTextVariable("ADDITIONAL_STRING", GameTexts.FindText("str_town_new_tournament_text"), false);
      else
        MBTextManager.SetTextVariable("ADDITIONAL_STRING", GameTexts.FindText("str_town_empty_arena_text"), false);
      if (PlayerTownVisitCampaignBehavior.CheckAndOpenNextLocation(args))
        return;
      args.MenuTitle = new TextObject("{=mMU3H6HZ}Arena");
    }

    public static bool game_menu_town_manage_town_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Manage;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      bool disableOption;
      TextObject disabledText;
      return MenuHelper.SetOptionProperties(args, Campaign.Current.Models.SettlementAccessModel.CanMainHeroDoSettlementAction(currentSettlement, SettlementAccessModel.SettlementAction.ManageTown, out disableOption, out disabledText), disableOption, disabledText);
    }

    public static bool game_menu_town_manage_town_cheat_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Manage;
      return GameManagerBase.Current.IsDevelopmentMode && Settlement.CurrentSettlement.IsTown && Settlement.CurrentSettlement.OwnerClan.Leader != Hero.MainHero;
    }

    private static bool game_menu_town_keep_open_stash_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.OpenStash;
      return Settlement.CurrentSettlement.OwnerClan == Clan.PlayerClan && !Settlement.CurrentSettlement.Town.IsOwnerUnassigned;
    }

    private static void game_menu_town_keep_open_stash_on_consequence(MenuCallbackArgs args)
    {
      InventoryManager.OpenScreenAsStash(Settlement.CurrentSettlement.Stash);
    }

    private static bool game_menu_manage_garrison_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.ManageGarrison;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      return currentSettlement.OwnerClan == Clan.PlayerClan && currentSettlement.MapFaction == Hero.MainHero.MapFaction && currentSettlement.IsFortification;
    }

    private static bool game_menu_manage_castle_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Manage;
      return Settlement.CurrentSettlement.OwnerClan == Clan.PlayerClan && Settlement.CurrentSettlement.IsCastle;
    }

    private static void game_menu_manage_garrison_on_consequence(MenuCallbackArgs args)
    {
      Settlement currentSettlement = Hero.MainHero.CurrentSettlement;
      if (currentSettlement.Town.GarrisonParty == null)
        currentSettlement.AddGarrisonParty();
      PartyScreenManager.OpenScreenAsManageTroops(currentSettlement.Town.GarrisonParty);
    }

    private static bool game_menu_leave_troops_garrison_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.DonateTroops;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      if (currentSettlement.OwnerClan == Clan.PlayerClan || currentSettlement.MapFaction != Hero.MainHero.MapFaction || !currentSettlement.IsFortification)
        return false;
      return currentSettlement.Town.GarrisonParty == null || currentSettlement.Town.GarrisonParty.Party.PartySizeLimit > currentSettlement.Town.GarrisonParty.Party.NumberOfAllMembers;
    }

    private static void game_menu_leave_troops_garrison_on_consequece(MenuCallbackArgs args)
    {
      PartyScreenManager.OpenScreenAsDonateGarrisonWithCurrentSettlement();
    }

    private static bool game_menu_town_town_streets_on_condition(MenuCallbackArgs args)
    {
      bool disableOption;
      TextObject disabledText;
      bool canPlayerDo = Campaign.Current.Models.SettlementAccessModel.CanMainHeroAccessLocation(Settlement.CurrentSettlement, "center", out disableOption, out disabledText);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "center")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return MenuHelper.SetOptionProperties(args, canPlayerDo, disableOption, disabledText);
    }

    private static void game_menu_town_town_streets_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(LocationComplex.Current.GetLocationWithId("center"));
    }

    private static void game_menu_town_lordshall_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "lordshall");
    }

    private static void game_menu_castle_lordshall_on_consequence(MenuCallbackArgs args)
    {
      SettlementAccessModel.AccessDetails accessDetails;
      Campaign.Current.Models.SettlementAccessModel.CanMainHeroEnterLordsHall(Settlement.CurrentSettlement, out accessDetails);
      if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.FullAccess)
        PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "lordshall");
      else if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.LimitedAccess && accessDetails.LimitedAccessSolution == SettlementAccessModel.LimitedAccessSolution.Bribe)
      {
        if (Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement) > 0)
          GameMenu.SwitchToMenu("castle_lords_hall_bribe");
        else
          PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "lordshall");
      }
      else
        Debug.FailedAssert("invalid LimitedAccessSolution or AccessLevel for castle lord's hall", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\CampaignBehaviors\\PlayerTownVisitCampaignBehavior.cs", nameof (game_menu_castle_lordshall_on_consequence), 1182);
    }

    private static void game_menu_town_keep_bribe_pay_bribe_on_consequence(MenuCallbackArgs args)
    {
      BribeGuardsAction.Apply(Settlement.CurrentSettlement, Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement));
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      GameMenu.ActivateGameMenu("town_keep");
    }

    private static void game_menu_castle_lordshall_bribe_on_consequence(MenuCallbackArgs args)
    {
      BribeGuardsAction.Apply(Settlement.CurrentSettlement, Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement));
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "lordshall");
    }

    private static void game_menu_lordshall_cheat_on_consequence(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "lordshall");
    }

    private static void game_menu_dungeon_cheat_on_consequence(MenuCallbackArgs ARGS)
    {
      GameMenu.SwitchToMenu("castle_dungeon");
    }

    private static void game_menu_town_dungeon_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "prison");
    }

    private static void game_menu_castle_dungeon_on_consequence(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "prison");
    }

    private static void game_menu_keep_dungeon_on_consequence(MenuCallbackArgs args)
    {
      GameMenu.SwitchToMenu("castle_dungeon");
    }

    private static void game_menu_town_town_tavern_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "tavern");
    }

    private static void game_menu_town_town_arena_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      PlayerTownVisitCampaignBehavior.OpenMissionWithSettingPreviousLocation("center", "arena");
    }

    private static void game_menu_town_town_market_on_consequence(MenuCallbackArgs args)
    {
      LocationEncounter locationEncounter = PlayerEncounter.LocationEncounter;
      InventoryManager. (Settlement.CurrentSettlement.ItemRoster, (SettlementComponent) Settlement.CurrentSettlement.Town);
    }

    private static bool game_menu_town_town_leave_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Leave;
      return MobileParty.MainParty.Army == null || MobileParty.MainParty.Army.LeaderParty == MobileParty.MainParty;
    }

    private static void game_menu_settlement_leave_on_consequence(MenuCallbackArgs args)
    {
      PlayerEncounter.LeaveSettlement();
      PlayerEncounter.Finish();
      Campaign.Current.SaveHandler.SignalAutoSave();
    }

    private static void settlement_wait_on_init(MenuCallbackArgs args)
    {
      TextObject text1 = args.MenuContext.GameMenu.GetText();
      TextObject variable1 = Hero.MainHero.IsPrisoner ? Hero.MainHero.PartyBelongedToAsPrisoner.Settlement.Name : Settlement.CurrentSettlement.Name;
      int captiveTimeInDays = PlayerCaptivity.CaptiveTimeInDays;
      TextObject text2;
      if (captiveTimeInDays == 0)
      {
        text2 = GameTexts.FindText("str_prisoner_of_settlement_menu_text");
      }
      else
      {
        text2 = GameTexts.FindText("str_prisoner_of_settlement_for_days_menu_text");
        text2.SetTextVariable("NUMBER_OF_DAYS", captiveTimeInDays);
        text2.SetTextVariable("PLURAL", captiveTimeInDays > 1 ? 1 : 0);
      }
      text2.SetTextVariable("SETTLEMENT_NAME", variable1);
      TextObject variable2 = text2;
      text1.SetTextVariable("CAPTIVITY_TEXT", variable2);
    }

    private static void game_menu_village_on_init(MenuCallbackArgs args)
    {
      PlayerTownVisitCampaignBehavior.SetIntroductionText(Settlement.CurrentSettlement, false);
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      SettlementAccessModel settlementAccessModel = Campaign.Current.Models.SettlementAccessModel;
      Settlement currentSettlement = Settlement.CurrentSettlement;
      Settlement settlement = currentSettlement;
      SettlementAccessModel.AccessDetails accessDetails;
      ref SettlementAccessModel.AccessDetails local = ref accessDetails;
      settlementAccessModel.CanMainHeroEnterSettlement(settlement, out local);
      if (currentSettlement != null)
      {
        Village village = currentSettlement.Village;
        if (accessDetails.AccessLevel == SettlementAccessModel.AccessLevel.NoAccess && accessDetails.AccessLimitationReason == SettlementAccessModel.AccessLimitationReason.VillageIsLooted)
          GameMenu.SwitchToMenu("village_looted");
      }
      args.MenuTitle = new TextObject("{=Ua6CNLBZ}Village");
    }

    private static void game_menu_castle_on_init(MenuCallbackArgs args)
    {
      MobileParty garrisonParty = Settlement.CurrentSettlement.Town.GarrisonParty;
      if ((garrisonParty != null ? (garrisonParty.MemberRoster.Count <= 0 ? 1 : 0) : 0) != 0)
        DestroyPartyAction.Apply((PartyBase) null, Settlement.CurrentSettlement.Town.GarrisonParty);
      PlayerTownVisitCampaignBehavior.SetIntroductionText(Settlement.CurrentSettlement, true);
      PlayerTownVisitCampaignBehavior.UpdateMenuLocations(args.MenuContext.GameMenu.StringId);
      if (Campaign.Current.GameMenuManager.NextLocation != null)
      {
        PlayerEncounter.LocationEncounter.CreateAndOpenMissionController(Campaign.Current.GameMenuManager.NextLocation, Campaign.Current.GameMenuManager.PreviousLocation);
        Campaign.Current.GameMenuManager.NextLocation = (Location) null;
        Campaign.Current.GameMenuManager.PreviousLocation = (Location) null;
      }
      args.MenuTitle = new TextObject("{=sVXa3zFx}Castle");
    }

    private static bool game_menu_castle_lordshall_bribe_pay_bribe_on_condition(
      MenuCallbackArgs args)
    {
      int toEnterLordsHall = Campaign.Current.Models.BribeCalculationModel.GetBribeToEnterLordsHall(Settlement.CurrentSettlement);
      MBTextManager.SetTextVariable("AMOUNT", toEnterLordsHall);
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.FindAll((Func<string, bool>) (x => x == "lordshall")).ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      if (Hero.MainHero.Gold < toEnterLordsHall)
      {
        args.Tooltip = new TextObject("{=d0kbtGYn}You don't have enough gold.");
        args.IsEnabled = false;
      }
      return toEnterLordsHall > 0;
    }

    private static bool game_menu_village_village_center_on_condition(MenuCallbackArgs args)
    {
      List<Location> list = Settlement.CurrentSettlement.LocationComplex.GetListOfLocations().ToList<Location>();
      MenuHelper.SetIssueAndQuestDataForLocations(args, list);
      args.optionLeaveType = GameMenuOption.LeaveType.Mission;
      return Settlement.CurrentSettlement.Village.VillageState == Village.VillageStates.Normal;
    }

    private static void game_menu_village_village_center_on_consequence(MenuCallbackArgs args)
    {
      (PlayerEncounter.LocationEncounter as VillageEncounter).CreateAndOpenMissionController(LocationComplex.Current.GetLocationWithId("village_center"), (Location) null, (CharacterObject) null, (string) null);
    }

    private static bool game_menu_village_buy_good_on_condition(MenuCallbackArgs args)
    {
      Village village = Settlement.CurrentSettlement.Village;
      if (village.VillageState == Village.VillageStates.BeingRaided)
        return false;
      args.optionLeaveType = GameMenuOption.LeaveType.Trade;
      if (village.VillageState == Village.VillageStates.Normal && village.Owner.ItemRoster.Count > 0)
      {
        foreach ((ItemObject, float) production in (List<(ItemObject, float)>) village.VillageType.Productions)
          ;
        return true;
      }
      if (village.Gold > 0)
      {
        args.Tooltip = new TextObject("{=FbowXAC0}There are no available products right now.");
        return true;
      }
      args.IsEnabled = false;
      args.Tooltip = new TextObject("{=bmfo7CaO}Village shop is not available right now.");
      return true;
    }

    private static void game_menu_recruit_volunteers_on_consequence(MenuCallbackArgs args)
    {
    }

    private static bool game_menu_recruit_volunteers_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Recruit;
      return !Settlement.CurrentSettlement.IsVillage || Settlement.CurrentSettlement.Village.VillageState == Village.VillageStates.Normal;
    }

    private static bool game_menu_village_wait_on_condition(MenuCallbackArgs args)
    {
      Village village = Settlement.CurrentSettlement.Village;
      args.optionLeaveType = GameMenuOption.LeaveType.Wait;
      return village.VillageState == Village.VillageStates.Normal;
    }

    private static bool game_menu_town_wait_on_condition(MenuCallbackArgs args)
    {
      args.optionLeaveType = GameMenuOption.LeaveType.Wait;
      MBTextManager.SetTextVariable("CURRENT_SETTLEMENT", Settlement.CurrentSettlement.EncyclopediaLinkWithName, false);
      return true;
    }

    public static void settlement_player_unconscious_continue_on_consequence(MenuCallbackArgs args)
    {
      Settlement currentSettlement = MobileParty.MainParty.CurrentSettlement;
      GameMenu.SwitchToMenu(currentSettlement.IsVillage ? "village" : (currentSettlement.IsCastle ? "castle" : "town"));
    }

    private static void SetIntroductionText(Settlement settlement, bool fromKeep)
    {
      TextObject textObject = new TextObject();
      if (settlement.IsTown && !fromKeep)
        textObject = settlement.OwnerClan != Clan.PlayerClan ? new TextObject("{=UWzQsHA2}{SETTLEMENT_LINK} is governed by {LORD.LINK}, {FACTION_OFFICIAL} of the {FACTION_TERM}. {PROSPERITY_INFO} {MORALE_INFO}") : new TextObject("{=kXVHwjoV}You have arrived at your fief of {SETTLEMENT_LINK}. {PROSPERITY_INFO} {MORALE_INFO}");
      else if (settlement.IsTown & fromKeep)
        textObject = settlement.OwnerClan != Clan.PlayerClan ? new TextObject("{=q3wD0rbq}{SETTLEMENT_LINK} is governed by {LORD.LINK}, {FACTION_OFFICIAL} of the {FACTION_TERM}. {KEEP_INFO}") : new TextObject("{=u0Dc5g4Z}You are in your town of {SETTLEMENT_LINK}. {KEEP_INFO}");
      else if (settlement.IsCastle)
        textObject = settlement.OwnerClan != Clan.PlayerClan ? new TextObject("{=4pmvrnmN}The castle of {SETTLEMENT_LINK} is owned by {LORD.LINK}, {FACTION_OFFICIAL} of the {FACTION_TERM}. {KEEP_INFO}") : new TextObject("{=dA8RGoQ1}You have arrived at {SETTLEMENT_LINK}. {KEEP_INFO}");
      else if (settlement.IsVillage)
        textObject = settlement.OwnerClan != Clan.PlayerClan ? new TextObject("{=RVDojUOM}The lands around {SETTLEMENT_LINK} are owned mostly by {LORD.LINK}, {FACTION_OFFICIAL} of the {FACTION_TERM}. {PROSPERITY_INFO}") : new TextObject("{=M5iR1e5h}You have arrived at your fief of {SETTLEMENT_LINK}. {PROSPERITY_INFO}");
      settlement.OwnerClan.Leader.SetPropertiesToTextObject(textObject, "LORD");
      string stringId = settlement.OwnerClan.Leader.MapFaction.Culture.StringId;
      if (settlement.OwnerClan.Leader.IsFemale)
        stringId += "_f";
      if (settlement.OwnerClan.Leader == Hero.MainHero && !Hero.MainHero.MapFaction.IsKingdomFaction)
      {
        textObject.SetTextVariable("FACTION_TERM", Hero.MainHero.Clan.EncyclopediaLinkWithName);
        textObject.SetTextVariable("FACTION_OFFICIAL", new TextObject("{=hb30yQPN}leader"));
      }
      else
      {
        textObject.SetTextVariable("FACTION_TERM", settlement.MapFaction.EncyclopediaLinkWithName);
        if (settlement.OwnerClan.MapFaction.IsKingdomFaction && settlement.OwnerClan.Leader == settlement.OwnerClan.Leader.MapFaction.Leader)
          textObject.SetTextVariable("FACTION_OFFICIAL", GameTexts.FindText("str_faction_ruler", stringId));
        else
          textObject.SetTextVariable("FACTION_OFFICIAL", GameTexts.FindText("str_faction_official", stringId));
      }
      textObject.SetTextVariable("SETTLEMENT_LINK", settlement.EncyclopediaLinkWithName);
      settlement.SetPropertiesToTextObject(textObject, "SETTLEMENT_OBJECT");
      string variation = settlement.SettlementComponent.GetProsperityLevel().ToString();
      if (settlement.IsTown && settlement.Town.InRebelliousState || settlement.IsVillage && settlement.Village.Bound.Town.InRebelliousState)
      {
        textObject.SetTextVariable("PROSPERITY_INFO", GameTexts.FindText("str_settlement_rebellion"));
        textObject.SetTextVariable("MORALE_INFO", "");
      }
      else if (settlement.IsTown)
      {
        textObject.SetTextVariable("PROSPERITY_INFO", GameTexts.FindText("str_town_long_prosperity_1", variation));
        textObject.SetTextVariable("MORALE_INFO", PlayerTownVisitCampaignBehavior.SetTownMoraleText(settlement));
      }
      else if (settlement.IsVillage)
        textObject.SetTextVariable("PROSPERITY_INFO", GameTexts.FindText("str_village_long_prosperity", variation));
      textObject.SetTextVariable("KEEP_INFO", "");
      if (fromKeep && LocationComplex.Current != null && !LocationComplex.Current.GetLocationWithId("lordshall").GetCharacterList().Any<LocationCharacter>((Func<LocationCharacter, bool>) (x => x.Character.IsHero)))
        textObject.SetTextVariable("KEEP_INFO", "{=OgkSLkFi}There is nobody in the lord's hall.");
      MBTextManager.SetTextVariable("SETTLEMENT_INFO", textObject, false);
    }

    private static TextObject SetTownMoraleText(Settlement settlement)
    {
      string str = "str_settlement_morale_high_prosperity";
      SettlementComponent.ProsperityLevel prosperityLevel = settlement.SettlementComponent.GetProsperityLevel();
      string id;
      if ((double) settlement.Town.Loyalty < 25.0)
        id = prosperityLevel > SettlementComponent.ProsperityLevel.Low ? (prosperityLevel > SettlementComponent.ProsperityLevel.Mid ? "str_settlement_morale_rebellious_prosperity" : "str_settlement_morale_rebellious_average") : "str_settlement_morale_rebellious_adversity";
      else if ((double) settlement.Town.Loyalty < 65.0)
      {
        if (prosperityLevel <= SettlementComponent.ProsperityLevel.Low)
          str = "str_settlement_morale_medium_adversity";
        id = prosperityLevel > SettlementComponent.ProsperityLevel.Mid ? "str_settlement_morale_medium_prosperity" : "str_settlement_morale_medium_average";
      }
      else
        id = prosperityLevel > SettlementComponent.ProsperityLevel.Low ? (prosperityLevel > SettlementComponent.ProsperityLevel.Mid ? "str_settlement_morale_high_prosperity" : "str_settlement_morale_high_average") : "str_settlement_morale_high_adversity";
      return GameTexts.FindText(id);
    }

    [GameMenuInitializationHandler("town_guard")]
    [GameMenuInitializationHandler("menu_tournament_withdraw_verify")]
    [GameMenuInitializationHandler("menu_tournament_bet_confirm")]
    [GameMenuInitializationHandler("town_castle_not_enough_bribe")]
    [GameMenuInitializationHandler("settlement_player_unconscious")]
    [GameMenuInitializationHandler("castle")]
    [GameMenuInitializationHandler("town_castle_nobody_inside")]
    [GameMenuInitializationHandler("encounter_interrupted")]
    [GameMenuInitializationHandler("encounter_interrupted_siege_preparations")]
    [GameMenuInitializationHandler("castle_dungeon")]
    [GameMenuInitializationHandler("encounter_interrupted_raid_started")]
    public static void game_menu_town_menu_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetBackgroundMeshName(Settlement.CurrentSettlement.SettlementComponent.WaitMeshName);
    }

    [GameMenuInitializationHandler("town_arena")]
    public static void game_menu_town_menu_arena_on_init(MenuCallbackArgs args)
    {
      string name = Settlement.CurrentSettlement.Culture.StringId + "_arena";
      args.MenuContext.SetBackgroundMeshName(name);
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/arena");
    }

    [GameMenuInitializationHandler("village_hostile_action")]
    [GameMenuInitializationHandler("force_volunteers_village")]
    [GameMenuInitializationHandler("force_supplies_village")]
    [GameMenuInitializationHandler("raid_village_no_resist_warn_player")]
    [GameMenuInitializationHandler("raid_village_resisted")]
    [GameMenuInitializationHandler("village_loot_no_resist")]
    [GameMenuInitializationHandler("village_take_food_confirm")]
    [GameMenuInitializationHandler("village_press_into_service_confirm")]
    [GameMenuInitializationHandler("menu_press_into_service_success")]
    [GameMenuInitializationHandler("menu_village_take_food_success")]
    public static void game_menu_village_menu_on_init(MenuCallbackArgs args)
    {
      Village village = Settlement.CurrentSettlement.Village;
      args.MenuContext.SetBackgroundMeshName(village.WaitMeshName);
    }

    [GameMenuInitializationHandler("town_keep")]
    public static void game_menu_town_menu_keep_on_init(MenuCallbackArgs args)
    {
      string name = Settlement.CurrentSettlement.Culture.StringId + "_keep";
      args.MenuContext.SetBackgroundMeshName(name);
      args.MenuContext.SetPanelSound("event:/ui/panels/settlement_keep");
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/keep");
    }

    [GameMenuEventHandler("town", "manage_production", GameMenuEventHandler.EventType.OnConsequence)]
    public static void game_menu_ui_town_manage_town_on_consequence(MenuCallbackArgs args)
    {
      args.MenuContext.OpenTownManagement();
    }

    [GameMenuEventHandler("town_keep", "manage_production", GameMenuEventHandler.EventType.OnConsequence)]
    public static void game_menu_ui_town_castle_manage_town_on_consequence(MenuCallbackArgs args)
    {
      args.MenuContext.OpenTownManagement();
    }

    [GameMenuEventHandler("village", "trade", GameMenuEventHandler.EventType.OnConsequence)]
    private static void game_menu_ui_village_buy_good_on_consequence(MenuCallbackArgs args)
    {
      InventoryManager.OpenScreenAsTrade(Settlement.CurrentSettlement.ItemRoster, (SettlementComponent) Settlement.CurrentSettlement.Village);
    }

    [GameMenuEventHandler("village", "manage_production", GameMenuEventHandler.EventType.OnConsequence)]
    private static void game_menu_ui_village_manage_village_on_consequence(MenuCallbackArgs args)
    {
      args.MenuContext.OpenTownManagement();
    }

    [GameMenuEventHandler("village", "recruit_volunteers", GameMenuEventHandler.EventType.OnConsequence)]
    [GameMenuEventHandler("town_backstreet", "recruit_volunteers", GameMenuEventHandler.EventType.OnConsequence)]
    [GameMenuEventHandler("town", "recruit_volunteers", GameMenuEventHandler.EventType.OnConsequence)]
    private static void game_menu_ui_recruit_volunteers_on_consequence(MenuCallbackArgs args)
    {
      args.MenuContext.OpenRecruitVolunteers();
    }

    [GameMenuInitializationHandler("prisoner_wait")]
    private static void wait_menu_ui_prisoner_wait_on_init(MenuCallbackArgs args)
    {
      if (Hero.MainHero.IsFemale)
        args.MenuContext.SetBackgroundMeshName("wait_captive_female");
      else
        args.MenuContext.SetBackgroundMeshName("wait_captive_male");
    }

    [GameMenuInitializationHandler("town_backstreet")]
    public static void game_menu_town_menu_backstreet_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/tavern");
    }

    [GameMenuInitializationHandler("town_enemy_town_keep")]
    [GameMenuInitializationHandler("town_keep_dungeon")]
    [GameMenuInitializationHandler("town_keep_bribe")]
    public static void game_menu_town_menu_keep_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetBackgroundMeshName(Settlement.CurrentSettlement.SettlementComponent.WaitMeshName);
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/keep");
    }

    [GameMenuInitializationHandler("town_wait_menus")]
    [GameMenuInitializationHandler("town_wait")]
    public static void game_menu_town_menu_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/city");
      args.MenuContext.SetBackgroundMeshName(Settlement.CurrentSettlement.SettlementComponent.WaitMeshName);
    }

    [GameMenuInitializationHandler("town")]
    public static void game_menu_town_menu_enter_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetPanelSound("event:/ui/panels/settlement_city");
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/city");
      args.MenuContext.SetBackgroundMeshName(Settlement.CurrentSettlement.SettlementComponent.WaitMeshName);
    }

    [GameMenuInitializationHandler("village_wait_menus")]
    public static void game_menu_village_menu_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/village");
      Village village = Settlement.CurrentSettlement.Village;
      args.MenuContext.SetBackgroundMeshName(village.WaitMeshName);
    }

    [GameMenuInitializationHandler("village")]
    public static void game_menu_village__enter_menu_sound_on_init(MenuCallbackArgs args)
    {
      args.MenuContext.SetPanelSound("event:/ui/panels/settlement_village");
      args.MenuContext.SetAmbientSound("event:/map/ambient/node/settlements/2d/village");
      Village village = Settlement.CurrentSettlement.Village;
      args.MenuContext.SetBackgroundMeshName(village.WaitMeshName);
    }

    private void OnSettlementEntered(MobileParty party, Settlement settlement, Hero hero)
    {
      if (party == null || !party.IsMainParty)
        return;
      settlement.HasVisited = true;
      if ((double) MBRandom.RandomFloat <= 0.5 || !settlement.IsVillage && !settlement.IsTown)
        return;
      this.CheckPerkAndGiveRelation(party, settlement);
    }

    private void CheckPerkAndGiveRelation(MobileParty party, Settlement settlement)
    {
      bool isVillage = settlement.IsVillage;
      if (!((isVillage ? party.HasPerk(DefaultPerks.Scouting.WaterDiviner, true) : party.HasPerk(DefaultPerks.Scouting.Pathfinder, true)) & (isVillage ? this._lastTimeRelationGivenWaterDiviner.Equals(CampaignTime.Zero) || (double) this._lastTimeRelationGivenWaterDiviner.ElapsedDaysUntilNow >= 1.0 : this._lastTimeRelationGivenPathfinder.Equals(CampaignTime.Zero) || (double) this._lastTimeRelationGivenPathfinder.ElapsedDaysUntilNow >= 1.0)))
        return;
      Hero randomElement = settlement.Notables.GetRandomElement<Hero>();
      if (randomElement != null)
        ChangeRelationAction.ApplyRelationChangeBetweenHeroes(party.ActualClan.Leader, randomElement, 1);
      if (isVillage)
        this._lastTimeRelationGivenWaterDiviner = CampaignTime.Now;
      else
        this._lastTimeRelationGivenPathfinder = CampaignTime.Now;
    }

    private void OnSettlementLeft(MobileParty party, Settlement settlement)
    {
      if (party == null || !party.IsMainParty)
        return;
      Campaign.Current.IsMainHeroDisguised = false;
    }

    private void SwitchToMenuIfThereIsAnInterrupt(string currentMenuId)
    {
      string genericStateMenu = Campaign.Current.Models.EncounterGameMenuModel.GetGenericStateMenu();
      if (!(genericStateMenu != currentMenuId))
        return;
      if (!string.IsNullOrEmpty(genericStateMenu))
        GameMenu.SwitchToMenu(genericStateMenu);
      else
        GameMenu.ExitToLast();
    }
  }
}
